package org.zongf.learn.grpc.remote.impl;

import com.learn.grpc.grpc.HelloServiceGrpc;
import com.learn.grpc.hello.PingRequest;
import com.learn.grpc.hello.PingResponse;
import io.grpc.ManagedChannel;
import org.zongf.learn.grpc.remote.IHelloRpcRmtService;
import org.zongf.learn.grpc.starter.AbsGrpcRmtService;

/**
 * @author zongf
 * @since 2023-07-10
 **/
//@Service
public class HelloRpcRmtService extends AbsGrpcRmtService<HelloServiceGrpc.HelloServiceBlockingStub> implements IHelloRpcRmtService {

    @Override
    protected String getServiceName() {
        return "learn-grpc-spring-server";
    }

    @Override
    protected HelloServiceGrpc.HelloServiceBlockingStub newBlockingStub(ManagedChannel managedChannel) {
        return HelloServiceGrpc.newBlockingStub(managedChannel);
    }

    @Override
    public String ping(String name) {
        PingRequest request = PingRequest.newBuilder()
                .setContent(name)
                .build();
        PingResponse response = getBlockingStub().ping(request);

        return response.getData();
    }
}
